<template>
    <div class="shopcar-container">
    
    <div class="goods-list">

      <!-- 商品列表项区域 -->
      <div class="mui-card" v-for="(item,index) in goodsList" :key="index">
			<div class="mui-card-content">
				<div class="mui-card-content-inner">
                    <mt-switch v-model="$store.getters.getGoodsStatus[item.id]" @change="changeSelected(item.id,$store.getters.getGoodsStatus[item.id])"></mt-switch>
                    <img :src="item.thumb_path">
                    <div class="info">
                        <h1>{{item.title}}</h1>
                        <p>
                            <span class="price">￥{{item.sell_price}}</span>
                            <numbox style="height:25px" :initCount="$store.getters.getGoodsCount[item.id]" :goodsId="item.id"></numbox>
                            <a @click="removegoods(item.id,index)">删除</a>
                        </p>
                    </div>
				</div>
			</div>
		</div>

    </div>

    <!-- 结算区域 -->
    <div class="mui-card">
				<div class="mui-card-content">
					<div class="mui-card-content-inner jiesuan">
						<div class="left">
              <p>总计（不含运费）</p>
              <p>已勾选商品 <span class="red"></span>{{ $store.getters.getAllGoods.count }}件，总价 <span class="red">￥ {{ $store.getters.getAllGoods.price }}</span></p>
            </div>
             <mt-button type="danger">去结算</mt-button>
					</div>
				</div>
			</div>
  </div>
</template>

<script>
import numbox from "../subComponent/shopcar_numbox.vue";
export default {
  components: {
    numbox
  },
  data(){
      return{
          goodsList:[]
      }
  },
  created(){
      this.getGoodslist()
  },
  methods:{
      getGoodslist(){
          var countId = []
          this.$store.state.car.forEach(element => {
              countId.push(element.id)
          });
          if(countId.length <= 0) return 
          this.$http.get('api/goods/getshopcarlist/'+countId.join(',')).then(result => {
              if(result.data.status === 0){
                  this.goodsList = result.data.message
              }
          })
      },
      removegoods(id,index){
        this.goodsList.splice(index,1)
        this.$store.commit('removegoods',id)
      },
      changeSelected(id,status){
        this.$store.commit('changeSelected',{id,status})
      }
  }
};
</script>

<style lang = 'less' scoped>
.shopcar-container {
  background-color: #eee;
  overflow: hidden;
  .goods-list {
    .mui-card-content-inner {
      display: flex;
      align-items: center;
    }
    img {
      width: 60px;
      margin: 0 5px;
    }
    h1 {
      font-size: 13px;
    }
    .info {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .price {
        color: red;
        font-weight: bold;
      }
      p{
          margin: 0;
      }
    }
  }
  .jiesuan {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .red {
      color: red;
      font-weight: bold;
      font-size: 16px;
    }
  }
}
</style>